package com.iob.coin.entity.result;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.jena.rdf.model.*;

/**
 * @Author: GuoXinyuan
 * @Date: 2021/6/9
 * 通过图谱查询产生的result
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class TargetResult extends Result{

    Result sourceSubject; //产生这个result所使用的subjectResource

    Result sourceProperty; //产生这个result所使用的属性result

    Result sourceObject; //产生这个result所使用的的objectResource
    public TargetResult(RDFNode rdfNode){
        super(rdfNode);
    }

    public Statement getStatement(){
        if(sourceSubject!=null){
            return ResourceFactory.createStatement(
                    sourceSubject.getRdfNode().asResource(),
                    sourceProperty.getRdfNode().as(Property.class),
                    super.rdfNode
            );
        }
        else if(sourceObject!=null){
            return ResourceFactory.createStatement(
                    super.rdfNode.asResource(),
                    sourceProperty.getRdfNode().as(Property.class),
                    sourceObject.getRdfNode()
            );
        }
        return null;
    }

}
